package com.example.administrator.yanfoxconn.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.activity.CanYinMainActivity;
import com.example.administrator.yanfoxconn.bean.CanYinInfo;
import com.example.administrator.yanfoxconn.utils.TimeDateUtils;

import org.w3c.dom.Text;

import java.util.List;

/**
 * 用途：餐飲巡檢 上傳圖片主界面
 * Created by Song on 2021/9/3.
 */
public class CanYinAdapter extends BaseAdapter {
    private CanYinMainActivity activity;
    private List<CanYinInfo> infoList;
    private String time;

    public CanYinAdapter(CanYinMainActivity activity, List<CanYinInfo> infoList,String time){
        this.activity = activity;
        this.infoList = infoList;
        this.time = time;
    }
    @Override
    public int getCount() {
        return infoList.size();
    }

    @Override
    public Object getItem(int i) {
        return infoList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_common_btn, null);

            holder.tvBtnCom = convertView.findViewById(R.id.tv_btn_com);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

         if(TimeDateUtils.minutesDeviation(infoList.get(position).getContent(),time)>0&&TimeDateUtils.minutesDeviation(time,infoList.get(position).getRemark())>0){
            holder.tvBtnCom.setBackgroundColor(activity.getResources().getColor(R.color.color_00CCFF));
        }else if (infoList.get(position).getYC().equals("N")){
            holder.tvBtnCom.setBackgroundColor(activity.getResources().getColor(R.color.color_cccccc));
        }else if (infoList.get(position).getYC().equals("A")){
            holder.tvBtnCom.setBackgroundColor(activity.getResources().getColor(R.color.color_42D42B));
        }else if (infoList.get(position).getYC().equals("Y")){
            holder.tvBtnCom.setBackgroundColor(activity.getResources().getColor(R.color.color_e84e4e));
        }
        holder.tvBtnCom.setText(infoList.get(position).getName());

        return convertView;
    }

    private class ViewHolder {
        public TextView tvBtnCom;
    }
}
